#encoding=utf-8

import logging.handlers
import logging
import os
import time

class Logger(object):
    def __init__(self,logger):


       # 第一步，创建一个logger
       self.logger = logging.getLogger()
       self.logger.setLevel(logging.DEBUG)

       # 第二步，创建一个handler，用于写入日志文件
       rq = time.strftime('%Y-%m-%d', time.localtime(time.time()))
       log_path='D:/pypronjects/tzzb-AppiumUI/result/Logs/'

       logfile = log_path + rq + '.log'

       # fh = logging.FileHandler(logfile, mode='a')
       fh = logging.handlers.TimedRotatingFileHandler(logfile, when='D', interval=1, backupCount=30)
       fh.setLevel(logging.DEBUG)  # 输出到file的log开关上

       # 第三步，定义handler的输出格式
       formatter = logging.Formatter("%(asctime)s-%(filename)s-[line:%(lineno)d]-%(levelname)s:%(message)s")
       fh.setFormatter(formatter)

       # 第四步，将logger添加到handler中
       self.logger.addHandler(fh)


    def get_log(self):
        return self.logger





# log = Logger("123").get_log()
#
# log.debug("debug")
# log.info("info")
# log.error("error")





